package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessMapper tbBusinessMapper;
    @Autowired
    private TbBusinessTrackRecordMapper businessTrackRecordMapper;
    @Autowired
    private ISysDictDataService iSysDictDataService;
    /**
     * 新增商机跟进记录
     */
    @Override
    public int insertBusinessTrackRecord(TbBusiness tbBusiness, TbBusinessTrackRecord tbBusinessTrackRecord) {
        //更新商机状态
        tbBusinessMapper.updateTbBusiness(tbBusiness);
        return businessTrackRecordMapper.insertBusinessTrackRecord(tbBusinessTrackRecord);
    }

    /**
     * 查询商机跟进记录列表
     */
    @Override
    public List<TbBusinessTrackRecord> selectBusinessTrackRecordList(Long id) {
        List<TbBusinessTrackRecord> result = businessTrackRecordMapper.selectBusinessTrackRecordList(id);
        //使用函数式编程的stream流简化
        /*result
        .forEach(businessTrackRecord->businessTrackRecord
                .setKeys(Arrays.stream(businessTrackRecord.getKeyItems().split(","))
                        .map(s -> iSysDictDataService.selectDictLabel("communication_point", s))
                        .collect(Collectors.toList()))
                );*/
        //根据keyItems从字典表里面查询字典标签,并添加到keys集合中
       /* for (TbBusinessTrackRecord businessTrackRecord : result) {
            String[] split = businessTrackRecord.getKeyItems().split(",");
            for (String s : split) {
                String dictLabel = iSysDictDataService.selectDictLabel("communication_point", s);
                businessTrackRecord.getKeys().add(dictLabel);
            }
        }*/
        return result;
    }
}
